package com.itheima.juc29;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author li
 * public static ExecutorService newCachedThreadPool()   创建一个没有上限的线程池(int类型的最大值)
 * public static ExecutorService newFixedThreadPool(int nThreads)    创建有上限的线程池
 */
public class MyThreadPoolDemo {
    public static void main(String[] args) throws InterruptedException {
        // 1.获取线程池对象
//        ExecutorService pool1 = Executors.newCachedThreadPool();
        ExecutorService pool1 = Executors.newFixedThreadPool(3);
        // 2.提交任务
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        pool1.submit(new MyRunnable());
        // 3.销毁线程池，一般不会销毁
//        pool1.shutdown();
    }
}
